package com.demo.pattern.single;

// 饿汉式 静态代码块
public class DemoTest2 {

    public static void main(String[] args) {
        System.out.println(Single2.getInstance() == Single2.getInstance());
    }
}

class Single2 {
    // 私有构造方法，外部不能new
    private Single2() {
    }

    public static Single2 instance;

    static {
        instance = new Single2();
    }

    public static Single2 getInstance() {
        return instance;
    }
}